/*----------------------------------------------------------------------------------*/
/*!
 * @file leveled.cxx
 * @brief scro level editor
 * @author steff
 *
 */
/*------------------------------------------------------------------------------------
------------------------------------------------------------------------------------*/

#include <stdlib.h>

#include "leveled.hxx"


SDL_Surface *screen;

yakwailog logger;

int main(int argNum, char *argA[])
{
	unsigned int start_menue = 0;
	struct leveled_config_struct leveled_config;
	logger.init("leveled", NULL, 2);
	logger.log(0, "starting up leveled...");
	switch(argNum)
	{
	    case 1:
	    	start_menue = 1;
	    break;
	    
	    case 2:
	    	if (strcmp(argA[1], "--help") == 0)
	    	{
	    		logger.log(0, "===============================================");
	    		logger.log(0, " USAGE FOLLOWS:");
	    		logger.log(0, " -l <filename>: load a level file at startup");
	    		logger.log(0, " -g <filename>: auto-generate a level file");
	    		logger.log(0, "===============================================");
	    	}
	    break;
	    
	    case 3:
			if (strcmp(argA[1], "-l") == 0)
			{
    	    	start_menue = 2;
			} else if (strcmp(argA[1], "-g") == 0)
			{
			    if (sli_generate_level(argA[2], 25, 150) == 0)
			    {
					printf("level %s generated successfully.\n", argA[2]);
			    } else
			    {
					printf("there was an error generating %s.\n", argA[2]);
			    }
			}
	    break;
	    
	    default:
			logger.log(1, "invalid amount of parameters... ignoring");
	    	start_menue = 1;
	    break;
	}
	
	//FIXME load settings
	leveled_config = leveled_config_load_settings();
	
	if (start_menue > 0)
	{
		if (TTF_Init() == -1) logger.log(2, "ttf init error");
		if (initEnv("leveled", leveled_config.x, leveled_config.y, leveled_config.bpp, leveled_config.flags) == 0) logger.log(2, "sdl init error");
	    if (start_menue == 2) leveled_editor(argA[2]);
		main_menue();
		SDL_FreeSurface(screen);		
		SDL_Quit();
	}
	
	logger.log(0, "exiting...");
	logger.end();
	return 1;
}
